import { create } from "zustand";
import { persist } from "zustand/middleware";
import { produce } from "immer";
import { storage } from "./config";

const useSystemStore = create(
  persist(
    (set) => ({
      curModel: "local",
      softwareType: 1,
      ownModel: "A30",
      curRoute: "home",
      setCurModel: (curModel) =>
        set(
          produce((state) => {
            state.curModel = curModel;
          })
        ),
      setSoftwareType: (softwareType) =>
        set(
          produce((state) => {
            state.softwareType = softwareType;
          })
        ),
      setOwnModel: (model) =>
        set(
          produce((state) => {
            state.ownModel = model;
          })
        ),
      setCurRoute: (route) =>
        set(
          produce((state) => {
            state.curRoute = route;
          })
        ),
    }),
    {
      name: "system-storage",
      storage,
    }
  )
);
export default useSystemStore;
